import numpy, scipy.sparse
import sparsesvd
import  matplotlib.pyplot as plt


mat = numpy.random.rand(6, 5)
print(mat)
smat = scipy.sparse.csc_matrix(mat)
print(smat)
ut, s, vt = sparsesvd.sparsesvd(smat, 4)

'''
 6X5 = U1=6x4 ,实际输出的U为U1的转置，S=4x4，V1 = 5x4，实际输出的V1为V的转置
'''

#print(numpy.allclose([[1,2]], [[1,2]])) #比较俩个数字在误差范围内每一个元素是否相等
#print(numpy.dot([[1],[2]], [[2, 1]]))  #dot俩个数组的乘积

#b = numpy.array([[2],[1]])
#print(b.T)  #矩阵转置
#print(numpy.diag(s))  #分配到对角线上

u = ut.T

plt.title("u1-u2")
plt.xlabel("u1")
plt.ylabel("u2")
#u 有6行4列
k = 4
m = 6
for i in range(6):
    plt.scatter(u[i][0], u[i][1], s=20)

plt.show()

